// 获取证件照参数逻辑
export default {
	namespaced: true,
	state: {
		// 证件照参数信息：
		sizeList: uni.getStorageSync('size_list') || {},
		// 用户证件照
		userIdPhoto: uni.getStorageSync('user_id_photo') || [],
	},
	mutations: {
		updateSizeList(state, payload) {
			state.sizeList = {}
			uni.removeStorageSync('size_list')
			state.sizeList = payload
			uni.setStorageSync('size_list', payload)
		},
		updateUserIdPhoto(state, payload) {
			// 清空
			state.userIdPhoto = []
			uni.removeStorageSync('user_id_photo')
			// 转换
			let dataList = []
			if (payload.length === 1) {
				const data = payload[0]
				for (let i = 0; i < data.file_name.length; i++) {
					dataList.push({
						spec_id: data.check_result.spec_id, // 规格 ID
						file_name: data.file_name[i], // 文件名
						img_wm_url_list: data.img_wm_url_list[i], // 单张照片预览
						print_wm_url_list: data.print_wm_url_list[i], // 排版预览
						background_color: state.sizeList.configs[0].config_json.background_color[i] // 背景色
					})
				}
			} else {
				dataList = payload.map((item, index) => {
					return {
						spec_id: item.check_result.spec_id, // 规格 ID
						file_name: item.file_name[0], // 文件名
						img_wm_url_list: item.img_wm_url_list[0] || '', // 单张照片预览
						print_wm_url_list: item.print_wm_url_list[0] || '', // 排版预览
						background_color: state.sizeList.configs[index].config_json.background_color[0] // 背景色
					}
				})
			}
			state.userIdPhoto = dataList
			uni.setStorageSync('user_id_photo', dataList)
		},
		clearData(state) {
			state.sizeList = {}
			state.userIdPhoto = []
			uni.removeStorageSync('size_list')
			uni.removeStorageSync('user_id_photo')
		}
	},
	actions: {}
}